package com.zw.yzk.kabu.data.repository;

import com.zw.yzk.kabu.data.network.task.Task;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.GetVerifyCodeEntity;
import com.zw.yzk.kabu.data.network.service.GetVerifyCodeService;
import com.zw.yzk.kabu.data.network.task.GetVerifyCodeTask;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class GetVerifyCodeRepository extends CommonRepository {

    @Inject
    public GetVerifyCodeRepository() {

    }

    @Override
    protected Observable connectServer(Task task) {
        GetVerifyCodeService getVerifyCodeService = ServiceGenerator.createService(GetVerifyCodeService.class);
        GetVerifyCodeTask loginTask = (GetVerifyCodeTask) task;

        return getVerifyCodeService.getVerifyCode(loginTask.phone);
    }

    @Override
    protected Func1<GetVerifyCodeEntity, Observable> getServerData() {
        return new Func1<GetVerifyCodeEntity, Observable>() {
            @Override
            public Observable call(GetVerifyCodeEntity entity) {
                return Observable.just(entity.result.verifyCode);
            }
        };
    }

}
